package com.first.xiinn.model;

import java.sql.Blob;
import java.sql.SQLException;

import org.hibernate.Hibernate;

import com.first.core.web.model.BaseModel;
import com.google.gson.annotations.Expose;

public class BookCatalog extends BaseModel {
	/**
	 * 主键
	 */
	@Expose
	protected String catalogId;
	/**
	 * 章节
	 */
	@Expose
	protected String catalog;
	/**
	 * 标题
	 */
    @Expose
	protected String catalogName;
    
    @Expose
	protected String bookid;
		
    @Expose
 	protected String isopen;
    /**
     * 是否试阅读
     * 0否1是
     */
    @Expose
   protected String tryReading;
    @Expose
   	protected Blob catalogContent;
    
    @Expose
   	protected String catalogContentStr;

	public String getCatalogId() {
		return catalogId;
	}

	public void setCatalogId(String catalogId) {
		this.catalogId = catalogId;
	}


	public String getCatalog() {
		return catalog;
	}

	public void setCatalog(String catalog) {
		this.catalog = catalog;
	}

	public String getCatalogName() {
		return catalogName;
	}

	public void setCatalogName(String catalogName) {
		this.catalogName = catalogName;
	}

	public String getBookid() {
		return bookid;
	}

	public void setBookid(String bookid) {
		this.bookid = bookid;
	}

	public String getIsopen() {
		return isopen;
	}

	public void setIsopen(String isopen) {
		this.isopen = isopen;
	}

	public String getTryReading() {
		return tryReading;
	}

	public void setTryReading(String tryReading) {
		this.tryReading = tryReading;
	}

	public Blob getCatalogContent() {
		return catalogContent;
	}

	public void setCatalogContent(Blob catalogContent) {
		try {
			this.catalogContentStr = this.blobToString(catalogContent);
		} catch (Exception e) {
			e.printStackTrace();
		}
		this.catalogContent = catalogContent;
	}
		public static String blobToString(Blob blob) throws Exception {
			try {
				if (blob == null || blob.length() == 0) {
					return null;
				}
				return new String(blob.getBytes(1, (int) blob.length()));
			} catch (Exception e) {
				e.printStackTrace();
				throw new RuntimeException();
			}
		}
	public String getCatalogContentStr() {
		return catalogContentStr;
	}

	public void setCatalogContentStr(String catalogContentStr) {
		if(catalogContentStr!=null && !"".equals(catalogContentStr)){
			catalogContent = Hibernate.createBlob(catalogContentStr.getBytes());
		}
		this.catalogContentStr = catalogContentStr;
	}


    
    
    
}
